{template 'web/_header'}
{template 'tabs'}
{if $operation=='post'}

<div class="main">
    <form id="dataform" action="" method="post" class="form-horizontal form" onsubmit='return formcheck()'>
        <div class='panel panel-default'>
            <div class='panel-heading'>
                  商品信息     
            </div>
            <div class='panel-body'>
                
                   <ul class="nav nav-arrow-next nav-tabs" id="myTab">
                    <li class="active" ><a href="#tab_basic">商品设置</a></li>
                    <li><a href="#tab_act">活动设置</a></li>
                    <li><a href="#tab_sub">提供商家设置</a></li>
                    <li><a href="#tab_vip">特权设置</a></li>
                    {if p('verify')}<li><a href="#tab_verify">兑换设置</a></li>{/if}
                    <li><a href="#tab_notice">商家通知设置</a></li>
                    <li><a href="#tab_share">关注及分享设置</a></li>
                </ul> 
            {if !empty($item['id'])} 
                <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">商品连接(点击复制)</label>
                <div class="col-sm-9 col-xs-12">
                    <p class='form-control-static'><a href='javascript:;' title='点击复制连接' id='cp'>{php echo $this->createPluginMobileUrl('creditshop/detail',array('id'=>$item['id']))}</a></p>
                </div>
             </div>
                {/if}
                
                <div class="tab-content">
                    <div class="tab-pane  active" id="tab_basic">{template 'goods/basic'}</div>
                    <div class="tab-pane" id="tab_act">{template 'goods/act'}</div>
                    <div class="tab-pane" id="tab_sub">{template 'goods/sub'}</div>
                    <div class="tab-pane" id="tab_vip">{template 'goods/vip'}</div>
                    {if p('verify')}<div class="tab-pane" id="tab_verify">{template 'goods/verify'}</div>{/if}
                    <div class="tab-pane" id="tab_notice">{template 'goods/notice'}</div>
                    <div class="tab-pane" id="tab_share">{template 'goods/share'}</div>
            </div>
        <div class='panel-body'>
               
                    <div class="form-group"></div>
                   <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                    <div class="col-sm-9 col-xs-12">
                       {ife 'creditshop.goods' $item}
                            <input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1"  />
                            <input type="hidden" name="token" value="{$_W['token']}" />
                       {/if}
                       
                       <input type="button" name="back" onclick='history.back()' {ifp 'creditshopadv.add|creditshopadv.edit'}style='margin-left:10px;'{/if} value="返回列表" class="btn btn-default" />
                    </div>
        </div>
        </div>
                     
            </div>
    </form>
</div>
<script language='javascript'>
     window.optionchanged = false;
        require(['bootstrap'],function(){
             $('#myTab a').click(function (e) {
                 e.preventDefault();
                 $(this).tab('show');
             })
     });
    function formcheck(){
        
        if($('select[name=cate]').val()==''){
            $('#myTab a[href="#tab_basic"]').tab('show');
            Tip.focus($('select[name=cate]'),'请选择分类!');
            return false;
        }
        
        if($(':input[name=title]').val()==''){
            $('#myTab a[href="#tab_basic"]').tab('show');
            Tip.focus($(':input[name=title]'),'请填写商品名称!');
            return false;
        }
        return true;
    }
        function search_goods() {
             if( $.trim($('#search-kwd-goods').val())==''){
                 Tip.focus('#search-kwd-goods','请输入关键词');
                 return;
             }
		$("#module-menus-goods").html("正在搜索....")
		$.get('{php echo $this->createWebUrl('shop/query')}', {
			keyword: $.trim($('#search-kwd-goods').val())
		}, function(dat){
			$('#module-menus-goods').html(dat);
		});
	}
	function select_good(o) {
                              $("#goodsid").val(o.id);
							  $("#couponid").val('');
                               $(":input[name=thumb]").val(o.thumb);
                               $(".img-thumbnail").attr('src',o.thumb);
                               $(":input[name=title]").val(o.title);
                                $(":input[name=total]").val(o.total);
                                $(":input[name=price]").val(o.marketprice);
   	               $("#modal-module-menus-goods .close").click();
	}
	
	{if p('coupon')}
   function search_coupons() {

        $("#module-menus-coupon").html("正在搜索....")
        $.get('{php echo $this->createPluginWebUrl('coupon/coupon',array('op'=>'query'))}', {
            keyword: $.trim($('#search-kwd').val())
        }, function (dat) {
            $('#module-menus-coupon').html(dat);
        });
    }
    function select_coupon(o) {
    $("#goodsid").val('');
	
         $("#couponid").val(o.id);
		 
         $(":input[name=thumb]").val(o.thumb);
         $(".img-thumbnail").attr('src',o.thumb);
         $(":input[name=title]").val(o.couponname);
         $(":input[name=total]").val(o.total=='-1'?'':o.total);
		 $(":input[name=money]").val(o.money);
		 $(":input[name=credit]").val(o.credit);
		 $(":checkbox[name=usecredit2]").get(0).checked = o.usecredit2=='1';
         $(":input[name=price]").val('');
         $("#modal-module-menus-coupon .close").click();
    }
{/if}
</script>
 
{elseif $operation == 'display'}
<form action="" method="get" class='form form-horizontal'>
    <div class="panel panel-info">
        <div class="panel-heading">筛选</div>
        <div class="panel-body">
            <form action="./index.php" method="get" class="form-horizontal" plugins="form">
                <input type="hidden" name="c" value="site" />
                <input type="hidden" name="a" value="entry" />
                <input type="hidden" name="m" value="sz_yi" />
                <input type="hidden" name="do" value="plugin" />
                <input type="hidden" name="p"  value="creditshop" />
                <input type="hidden" name="method"  value="goods" />
                <input type="hidden" name="op" value="display" />
                <div class="form-group">
                  <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">关键词</label>
                    <div class="col-xs-12 col-sm-8 col-lg-9">
                        <input class="form-control" name="keyword" id="" type="text" value="{$_GPC['keyword']}" placeholder="可搜索商品标题/提供商户">
                    </div>
                </div>
                 <div class="form-group">
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">分类</label>
                       <div class="col-xs-12 col-sm-8 col-lg-9">
                           <select class='form-control' name='cate'>
                                <option value=''></option>
                                 {loop $category $cate}
                                 <option value='{$cate['id']}' {if $_GPC['cate']==$cate['id']}selected{/if}>{$cate['name']}</option>
                                 {/loop}
                            </select>
                     </div>
                </div>
                
                 <div class="form-group">
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">类型</label>
                       <div class="col-xs-12 col-sm-8 col-lg-9">
                       <select name='type' class='form-control'>
                          <option value='' {if $_GPC['type']==''}selected{/if}></option>
                          <option value='0' {if $_GPC['type']=='0'}selected{/if}>兑换</option>
                          <option value='1' {if $_GPC['type']=='1'}selected{/if} >抽奖</option>
                       </select> 
                     </div>
                </div>
                   <div class="form-group">
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">状态</label>
                       <div class="col-xs-12 col-sm-8 col-lg-9">
                       <select name='status' class='form-control'>
                          <option value='' {if $_GPC['status']==''}selected{/if}></option>
                          <option value='0' {if $_GPC['status']=='0'}selected{/if}>暂停</option>
                          <option value='1' {if $_GPC['status']=='1'}selected{/if} >开启</option>
                       </select> 
                     </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label"> </label>
                      <div class="col-xs-12 col-sm-2 col-lg-2">
                        <button class="btn btn-default"><i class="fa fa-search"></i> 搜索</button>
                    </div>
                </div>
        </div>
    </div>
    </form>
            
    <form action="" method="post">
    <div class='panel panel-default'>
        <div class='panel-heading' >
            商品管理 (数量: {$total} 条)
     
        </div>
        <div class='panel-body'>

            <table class="table">
                <thead>
                  <tr>
                        <th style="width:60px;">ID</th>
                        <th style="width:80px;">排序</th>
                        <th>商品标题</th>
                        <th style='width:80px;'>类型</th>      
                        <th style='width:150px;'>属性</th>      
                        
                        <th style='width:100px;'>消耗</th>
                  
                        <th style='width:100px;'>参与次数</th>
                        <th style='width:100px;'>浏览次数</th>
                        <th style='width:100px;' >状态</th>
                        <th style="">操作</th>
                    </tr>
                </thead>
                <tbody>
                    {loop $list $row}
                         <td>{$row['id']}</td>
                          <td>
                              {ifp 'creditshop.goods.edit'}
                              <input type="text" class="form-control" name="displayorder[{$row['id']}]" value="{$row['displayorder']}">
                               {else}
                              {$row['displayorder']}
                              {/if}
                          </td>
                          <td>
                              {if !empty($row['subtitle'])}<span class='label label-warning'>{$row['subtitle']}</span>{/if}
                              <span class='label label-primary'>{$category[$row['cate']]['name']}</span><br/>{$row['title']}
                          </td>
                          <td>
							  {if $pcoupon}
			  {if $row['goodstype']==1}
                              <span class='label label-warning'>优惠券</span>
                              {else}
                              <span class='label label-success'>商品</span>
                              {/if}
							  <br/>
							  {/if}
							  
							  {if $row['type']==1}
                              <span class='label label-danger'>抽奖</span>
                              {else}
                              <span class='label label-primary'>兑换</span>
                              {/if}
                               </td>
                         <td> 
                            <label data='{$row['istop']}' class='label label-default {if $row['istop']==1}label-info{else}{/if}'   {ifp 'creditshop.goods.edit'}onclick="setProperty(this,{$row['id']},'istop')"{/if}>置顶</label>
                            <label data='{$row['isrecommand']}' class='label label-default {if $row['isrecommand']==1}label-info{/if}' {ifp 'creditshop.goods.edit'}onclick="setProperty(this,{$row['id']},'isrecommand')"{/if}>推荐</label>
                            <label data='{$row['istime']}' class='label label-default {if $row['istime']==1}label-info{/if}' {ifp 'creditshop.goods.edit'}onclick="setProperty(this,{$row['id']},'istime')"{/if}>限时</label>
                         </td>
                         <td>{if $row['credit']>0}-{$row['credit']}积分<br/>{/if}
                              {if $row['money']>0}
                              -{$row['money']}现金
                              {/if}
                         </td>
                         <td>{$row['joins']}</td>
                         <td>{$row['views']}</td>
                           <td>     
                                <label data='{$item['status']}' class='label  label-default {if $row['status']==1}label-success{/if}' {ifp 'creditshopshop.goods.edit'}onclick="setProperty(this,{$item['id']},'status')"{/if}>{if $row['status']==1}开启{else}暂停{/if}</label>
                               
                         </td>
                         <td>
                             {ifp 'creditshop.goods.view|creditshop.goods.edit'}<a class='btn btn-default' href="{php echo $this->createPluginWebUrl('creditshop/goods',array('op'=>'post','id' => $row['id']));}" ><i class='fa fa-edit'></i></a>{/if}
                             {ifp 'creditshop.goods.delete'}<a class='btn btn-default' href="{php echo $this->createPluginWebUrl('creditshop/goods',array('op'=>'delete','id' => $row['id']));}" title='删除' onclick="return confirm('确定要删除该商品吗？');"><i class='fa fa-remove'></i></a>{/if}
                         </td>
            </tr>
                   {/loop}
                </tbody>
            </table>
            {$pager}
 
        </div>
        
            <div class='panel-footer'>
                   {ifp 'creditshop.goods.edit'}
                          <input name="submit" type="submit" class="btn btn-primary" value="提交排序">
                           <input type="hidden" name="token" value="{$_W['token']}" />
                           {/if}
                           
        {ifp 'creditshop.goods.add'}                   
                          <a class='btn btn-default' href="{php echo $this->createPluginWebUrl('creditshop/goods',array('op'=>'post'))}"><i class='fa fa-plus'></i> 添加商品</a>
                            {/if}
          </div>
      
    </div>
</form>

            <script language='javascript'>
                  function setProperty(obj, id, type) {
                   
                            $(obj).html($(obj).html() + "...");
                   
                            $.post("{php echo $this->createPluginWebUrl('creditshop/goods')}",{'op':'setgoodsproperty',id: id, type: type, data: obj.getAttribute("data")},function (d) {
                                            $(obj).html($(obj).html().replace("...", ""));
                                            if (type == 'status') {
                                                $(obj).html(d.data == '1' ? '显示' : '隐藏');
                                            }
                                            $(obj).attr("data", d.data); 
                                            if (d.result == 1) {
                                                $(obj).toggleClass("label-info");
                                            }
                                        }
                            , "json");
                        }
                </script>

{/if}
{template 'web/_footer'}
 
